# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=setuptools-git
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.2
pkgrel=1
pkgdesc="Setuptools revision control system plugin for Git (mingw-w64)"
arch=('any')
url='https://github.com/msabramo/setuptools-git'
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools"
         "git")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/msabramo/setuptools-git/archive/${pkgver}.tar.gz")
sha512sums=('368d56003a440c5be00685356b0aef97fdea4a84a6d4e56d59964833b55de4916353e061f2eebf2de4dac2df4783a0a1b2d58ba88e1a93979b38a2b62900c1c1')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  local _git_usr="$(git config user.email)"
  if [[ -z "$_git_usr" ]]; then
    warning "git config must be set."   
  else
    cd "${srcdir}/${_realname}-${pkgver}"

    ${MINGW_PREFIX}/bin/python setup.py test || warning "Tests failed!!!"
  fi
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
